package com.leyou.controller;

import com.leyou.common.constants.LyConstants;
import com.leyou.item.pojo.Category;
import com.leyou.server.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父id查询分类z
     */
    @GetMapping("/category/of/parent")
    public ResponseEntity<List<Category>> findCategoriesByPid(@RequestParam("pid") Long pid, HttpServletRequest request){
        List<Category> categories = categoryService.findCategoriesByPid(pid);
        //return ResponseEntity.status(HttpStatus.OK).body(categories);\
        return ResponseEntity.ok(categories);
    }
    /**
     * 根据分类ID集合查询分类对象集合
     */
    @GetMapping("/category/list")
    public ResponseEntity<List<Category>>findCategoriesByCids(
            @RequestParam ("ids") List<Long> ids,HttpServletRequest request
    ){
        List<Category> categoryList = categoryService.findCategoriesByCids(ids);
        System.out.println("AppToken: "+request.getHeader(LyConstants.APP_TOKEN_HEADER));
       return ResponseEntity.ok(categoryList);
    }
}



